class Board {
  width: number = 500;
  height: number = 700;

  init() {
    console.log("初始化棋盘");
  }

  private constructor() {}

  // 单例模式1
  /* private static _board?: Board;
  static createBoard(): Board {
    if (this._board) {
      return this._board;
    }

    this._board = new Board();
    return this._board;
  } */

  // 单例模式2: 一开始就会创建棋盘
  static readonly singleBoard = new Board();
}

// const b1 = Board.createBoard();
// const b2 = Board.createBoard();
// console.log(b1 === b2);

const b1 = Board.singleBoard;
const b2 = Board.singleBoard;
console.log(b1 === b2);
